<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Linux," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;Linux 用户名文件是 /etc/passwd 可以说是 Linux 系统中最重要的文件之一。如果这个文件出了问题，则无法正常登录 Linux 系统。 1234567891011[root@localhost ~]# cat /etc/passwd | headroot:x:0:0:root:/roo">
<meta name="keywords" content="Linux">
<meta property="og:type" content="article">
<meta property="og:title" content="Linux 用户名文件">
<meta property="og:url" content="https://hcldirgit.github.io/2017/09/03/1. Linux 基础/6. Linux 用户名文件/index.html">
<meta property="og:site_name" content="失落的乐章">
<meta property="og:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;Linux 用户名文件是 /etc/passwd 可以说是 Linux 系统中最重要的文件之一。如果这个文件出了问题，则无法正常登录 Linux 系统。 1234567891011[root@localhost ~]# cat /etc/passwd | headroot:x:0:0:root:/roo">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-09-01T08:11:14.612Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Linux 用户名文件">
<meta name="twitter:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;Linux 用户名文件是 /etc/passwd 可以说是 Linux 系统中最重要的文件之一。如果这个文件出了问题，则无法正常登录 Linux 系统。 1234567891011[root@localhost ~]# cat /etc/passwd | headroot:x:0:0:root:/roo">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://hcldirgit.github.io/2017/09/03/1. Linux 基础/6. Linux 用户名文件/"/>





  <title>Linux 用户名文件 | 失落的乐章</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', '85*****1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?87980c**************99ec5e26fb5";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>











  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">失落的乐章</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">技术面前，永远都是学生。</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-message">
          <a href="/message" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-external-link"></i> <br />
            
            留言
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://hcldirgit.github.io/2017/09/03/1. Linux 基础/6. Linux 用户名文件/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="失落的乐章">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/0.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="失落的乐章">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Linux 用户名文件</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-03T01:55:11+08:00">
                2017-09-03
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Linux 用户名文件是 <code>/etc/passwd</code> 可以说是 Linux 系统中最重要的文件之一。如果这个文件出了问题，则无法正常登录 Linux 系统。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># cat /etc/passwd | head</span></div><div class="line">root:x:0:0:root:/root:/bin/bash</div><div class="line">bin:x:1:1:bin:/bin:/sbin/nologin</div><div class="line">daemon:x:2:2:daemon:/sbin:/sbin/nologin</div><div class="line">adm:x:3:4:adm:/var/adm:/sbin/nologin</div><div class="line">lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin</div><div class="line">sync:x:5:0:sync:/sbin:/bin/sync</div><div class="line">shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown</div><div class="line">halt:x:7:0:halt:/sbin:/sbin/halt</div><div class="line">mail:x:8:12:mail:/var/spool/mail:/sbin/nologin</div><div class="line">uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;“head” 前面的 “|” 叫做管道符，它的作用是把前面的命令的输出再输入给后面的命令。</p>
<h2 id="用户名文件每个字段的含义"><a href="#用户名文件每个字段的含义" class="headerlink" title="用户名文件每个字段的含义"></a>用户名文件每个字段的含义</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<code>/etc/passwd</code> 由 <code>：</code> 分割成 7 个字段，每个字段的含义是：<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>1.用户名</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如第一行中的 root 就是用户名，代表用户帐号的字符串。用户名字符串可以是大小写字母、数字、减号（不能出现在首位）、点以及下划线，其他字符不合法。虽然用户名中可以出现点，但不建议使用，尤其是首位为点时，另外减号也不建议使用，因为庸医造成混淆。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>2.帐号口令</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;第二字段存放的就是该帐号的口令。为什么是 ‘x’ 呢？早起的 unix 系统口令是存放在这里，但基于安全因素，后来就将其到 ‘/etc/shadow’ 中了，这里只用一个 ‘x’ 代替。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>3.用户标识号</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这个数字代表用户标识号，也叫做 uid 。系统识别用户身份就是通过这个数字， 0 就是 root ，也就是说可以修改 test 用户的 uid 为 0 ，那么系统就会认为 root 和 test 为同一个账户。通常 uid 的取值范围是 0-65535 （但实际上已经可以支持到 4294967294），0 是超级用户 （root）的表示号，1-499 有系统保留，作为管理帐号，普通用户的表示号从 500 开始，如果自定义建立一个普通用户，可以看到该账户的标识号是大于或等于 500 的。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>4.组表示号</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这个数字表示组标识号，也叫做 gid 这个字段对应着 /etc/group 中的一条记录，其实 /etc/group 和 /etc/passwd 基本上类似。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>5.注释说明</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;该字段没有实际意义，通常记录该用户的一些属性，例如姓名、电话、地址等等。不过，当使用 finger 的功能时就回显示这些信息。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>6.用户家目录</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;当用户登录时就处在这个目录下。 root 的家目录是 /root，普通用户的家目录则为 /home/username ，这个字段是可以自定义的，比如建立一个普通用户 test1 ，要想让 test1 的家目录在 /data 目录下，只要修改 /etc/passwd 文件中的 test1 那行中的该字段为 /data 即可。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>7.shell</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;用户登录后要启动一个进程，用来将用户下达的指令传给内核，这就是 shell 。Linux 的 shell 有很多中 sh 、csh 、ksh 、tcsh 、bash等，而 Redhat /CentOS 的 shell 就是 bash 。查看 /etc/passwd 文件，该字段中除了 /bin/bash 外还有 /sbin/nologin 比较多，它表示不允许该帐号登录。如果想建立一个帐号不让它登录，那么就可以把该字段改成 /sbin/nologin 默认是 /bin/bash。</p>
<h2 id="chfn-更改用户的-finger"><a href="#chfn-更改用户的-finger" class="headerlink" title="chfn 更改用户的 finger"></a>chfn 更改用户的 finger</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在 /etc/passwd 文件中的第五个字段中所显示的信息，如何去设定：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">[root@localhost ~]<span class="comment"># chfn user11</span></div><div class="line">Changing finger information <span class="keyword">for</span> user11.</div><div class="line">Name []: user11</div><div class="line">Office []: user11<span class="string">'s office</span></div><div class="line"><span class="string">Office Phone []: 12345678</span></div><div class="line"><span class="string">Home Phone []: 123456789</span></div><div class="line"><span class="string"></span></div><div class="line"><span class="string">Finger information changed.</span></div><div class="line"><span class="string">[root@localhost ~]# grep '</span>user11<span class="string">' /etc/passwd</span></div><div class="line"><span class="string">user11:x:510:502:user11,user11'</span>s office,12345678,123456789:/home/user11:/sbin/nologin</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;‘chfn’ 命令可以修改用户的findger信息，比如name, office, office phone 以及 Home phone.修改完后，就会在/etc/passwd文件中的user11的那一行第五个字段中看到相关信息了，默认是空的。“grep” 命令，它是用来过滤指定关键词的行</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Linux/" rel="tag"># Linux</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/03/1. Linux 基础/61. Linux下使用iptables实现内网的ftp端口映射/" rel="next" title="Linux下使用iptables实现内网的ftp端口映射">
                <i class="fa fa-chevron-left"></i> Linux下使用iptables实现内网的ftp端口映射
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/03/1. Linux 基础/43.bash_profile和bashrc区别/" rel="prev" title="bash_profile和bashrc区别">
                bash_profile和bashrc区别 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/0.png"
               alt="失落的乐章" />
          <p class="site-author-name" itemprop="name">失落的乐章</p>
           
              <p class="site-description motion-element" itemprop="description">失落的乐章的Blog</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/">
                <span class="site-state-item-count">627</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hcldirgit" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#用户名文件每个字段的含义"><span class="nav-number">1.</span> <span class="nav-text">用户名文件每个字段的含义</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#chfn-更改用户的-finger"><span class="nav-number">2.</span> <span class="nav-text">chfn 更改用户的 finger</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">失落的乐章</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
